{extend name='table'}

{block name="button"}
<!--{if auth("remove")}-->
<button data-action='{:url("remove")}' data-table-id="FeedbackData" data-rule="id#{id}" data-confirm="确定要批量删除吗？" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</button>
<!--{/if}-->
{/block}

{block name="content"}
<div class="layui-tab layui-tab-card think-bg-white">
    <ul class="layui-tab-title">
        {foreach ['index'=>'意见反馈','recycle'=>'回 收 站'] as $k=>$v}
        {if isset($type) and $type eq $k}
        <li class="layui-this color-green" data-open="{:url('index')}?type={$k}">{$v}</li>
        {else}
        <li data-open="{:url('index')}?type={$k}">{$v}</li>
        {/if}{/foreach}
    </ul>
    <div class="layui-tab-content">
        {include file='help/feedback/index_search'}
        <table id="FeedbackData" data-url="{$request->url()}" data-target-search="form.form-search"></table>
    </div>
</div>
{/block}

{block name='script'}
<script>
    $(function () {
        // 初始化表格组件
        let $table = $('#FeedbackData').layTable({
            even: true, height: 'full', sort: {field: 'sort desc,id', type: 'desc'},
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'sort', title: '排序权重', align: 'center', width: 100, sort: true, templet: '#SortInputTpl'},
                {
                    title: '提交用户', minWidth: 200, width: '10%', templet: function (d) {
                        return showTableImage(d.user_headimg, true, '', (d.user_nickname || '') + " " + (d.user_phone || ''));
                    }
                },
                {field: 'phone', title: '联系电话', align: 'center', minWidth: 140, templet: '<div>{{d.phone||"-"}}</div>'},
                {field: 'content', title: '反馈意见', align: 'left', minWidth: 150, templet: '<div>{{d.content||"-"}}</div>'},
                {field: 'reply', title: '回复内容', align: 'left', minWidth: 150, templet: '<div>{{d.reply||"-"}}</div>'},
                {field: 'status', title: '显示状态', align: 'center', minWidth: 110, templet: '#StatusSwitchTpl'},
                {field: 'sync', title: '同步到常见问题', align: 'center', minWidth: 110, templet: '#ToProblemSwitchTpl'},
                {field: 'create_time', title: '创建时间', align: 'center', minWidth: 170, sort: true},
                {toolbar: '#toolbar', title: '操作面板', align: 'center', minWidth: 150, fixed: 'right'},
            ]]
        });

        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            let data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('state')}", data, 'post', function (ret) {
                let fn = () => $table.trigger('reload');
                ret.code > 0 ? fn() : $.msg.error(ret.info, 3, fn);
                return false;
            }, false);
        });

        // 同步到常见问题状态切换操作
        layui.form.on('switch(ToProblemSwitch)', function (obj) {
            let data = {id: obj.value, sync: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('sync')}", data, 'post', function (ret) {
                let fn = () => $table.trigger('reload');
                ret.code > 0 ? fn() : $.msg.error(ret.info, 3, fn);
                return false;
            }, false);
        });
    });
</script>

<!-- 列表排序权重模板 -->
<script type="text/html" id="SortInputTpl">
    <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已显示|已隐藏" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">已显示</b>' : '<b class="color-red">已隐藏</b>'}}
    <!--{/if}-->
</script>

<!-- 同步到常见问题切换模板 -->
<script type="text/html" id="ToProblemSwitchTpl">
    <!--{if auth("toproblem")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已同步|未同步" lay-filter="ToProblemSwitch" {{-d.sync>0?'checked':''}}/>
    <!--{else}-->
    {{-d.sync ? '<b class="color-green">已同步</b>' : '<b class="color-red">未同步</b>'}}
    <!--{/if}-->
</script>

<!-- 数据操作工具条模板 -->
<script type="text/html" id="toolbar">
    <!--{if auth('edit')}-->
    <a class="layui-btn layui-btn-primary layui-btn-sm" data-open='{:url("edit")}?id={{d.id}}'>编 辑</a>
    <!--{/if}-->

    <!--{if auth("remove")}-->
    <a class="layui-btn layui-btn-danger layui-btn-sm" data-confirm="确定要删除问题吗?" data-action="{:url('remove')}" data-value="id#{{d.id}}">删 除</a>
    <!--{/if}-->
</script>
{/block}